package main

import (
	"fmt"
	"unicode/utf8"
)

/**
1、使用range遍历pos，rune对
2、使用utf8.RuneCountInString获得字符数量
3、使用len获得字节长度
4、使用[]byte获得字节

*/
func main() {

	s := "Yes我爱慕课网"

	fmt.Printf("%X\n", s)

	for _, b := range []byte(s) {
		fmt.Printf("%X\n", b)
	}

	fmt.Println()

	for i, b := range s { // ch is a rune
		fmt.Printf("%d %X \n", i, b)
	}

	fmt.Println("Rune count:", utf8.RuneCountInString(s))

	bytes := []byte(s)

	for len(bytes) > 0 {
		ch, size := utf8.DecodeRune(bytes)
		bytes = bytes[size:]
		fmt.Printf("%c ", ch)
	}

	fmt.Println()

	for i, ch := range []rune(s) {
		fmt.Printf("(%d %c)", i, ch)
	}

	fmt.Println()

}
